using UnityEngine;

public class Attack7 : MonoBehaviour
{
	public GameObject effect;

	private Light mainlight;

	private int touchIndex;

	private Vector2 touchStart;

	private Vector2 touchEnd;

	private void Start()
	{
		StateManager.specialAttack = true;
		effect.SetActive(value: false);
		base.transform.parent = GameObject.FindGameObjectWithTag("Player").transform;
		base.transform.localPosition = new Vector3(0f, 1f, 0f);
		mainlight = GameObject.Find("Directional light").GetComponent<Light>();
		mainlight.GetComponent<Animation>()["SceneLight"].speed = -1f;
		mainlight.GetComponent<Animation>()["SceneLight"].time = mainlight.GetComponent<Animation>()["SceneLight"].length;
		mainlight.GetComponent<Animation>().Play("SceneLight");
	}

	private void Update()
	{
		if ((bool)effect && effect.active)
		{
			return;
		}
		int touchCount = UnityEngine.Input.touchCount;
		for (int i = 0; i < touchCount; i++)
		{
			Touch touch = UnityEngine.Input.GetTouch(i);
			if (touch.phase == TouchPhase.Began)
			{
				touchStart = touch.position;
				touchEnd = touchStart;
				touchIndex = i;
			}
			else if (i == touchIndex)
			{
				touchEnd = touch.position;
			}
			if (i == touchIndex && touch.phase == TouchPhase.Ended)
			{
				if (!(touchEnd.x / touchStart.x > 0.89f) || !(touchEnd.x / touchStart.x < 1.11f) || !(touchEnd.y / touchStart.y > 0.89f) || !(touchEnd.y / touchStart.y < 1.11f))
				{
					break;
				}
				StartAttack();
			}
		}
	}

	private void FixedUpdate()
	{
		if ((bool)effect && effect.active)
		{
			StateManager.specialEnergy -= 0.1f;
			if (StateManager.specialEnergy <= 5f)
			{
				EndAttack();
			}
		}
	}

	private void StartAttack()
	{
		GetComponent<AudioSource>().Play();
		StateManager.heightLimit = 4;
		mainlight.enabled = false;
		if ((bool)effect)
		{
			effect.SetActiveRecursively(state: true);
		}
	}

	private void EndAttack()
	{
		GetComponent<AudioSource>().Play();
		UnityEngine.Object.Destroy(effect);
		Invoke("EndEffect", 3f);
		StateManager.specialAttack = false;
	}

	private void EndEffect()
	{
		mainlight.enabled = true;
		mainlight.GetComponent<Animation>()["SceneLight"].speed = 1f;
		mainlight.GetComponent<Animation>().Play();
		StateManager.heightLimit = 3;
		UnityEngine.Object.Destroy(base.gameObject);
	}
}
